package com.styytech.dadabao.ui.my;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;

import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.styytech.dadabao.R;
import com.styytech.dadabao.base.BaseActivity;
import com.styytech.dadabao.constant.ConstantsServerUrl;
import com.styytech.dadabao.utils.NetworkUtils;
import com.styytech.dadabao.utils.SpUser;
import com.styytech.dadabao.widge.webview.ProgressWebView;

/**
 * Created by user on 2015/8/25.
 */
@ContentView(R.layout.recharge_webview_layout)
public class RechargeWebViewActivity extends BaseActivity {
    @ViewInject(R.id.baseweb_webview)
    private ProgressWebView baseweb_webview;
    StringBuffer url=new StringBuffer();
    double amount;
    int amount_final;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        amount=bundle.getDouble("amount");
        amount_final=(int)(amount*100);
        url.append(ConstantsServerUrl.server).append(ConstantsServerUrl.getRechargeUrl())
                .append("?token=").append(SpUser.getUserToken(RechargeWebViewActivity.this))
                .append("&amount=").append(amount_final).append("&terminalid=").append(NetworkUtils.getImeiId(this))
                .append("&userua=").append(baseweb_webview.getSettings().getUserAgentString())
                .append("&userip=").append(NetworkUtils.GetIp()).append("&identitytype=0").append("&terminaltype=0");
       /* url.append(ConstantsServerUrl.server).append(ConstantsServerUrl.getZFBUrl())
                .append("?token=").append(SpUser.getUserToken(RechargeWebViewActivity.this))
                .append("&money=").append(amount);*/


        initViews();
    }
    private void initViews(){
        setTopBar("充值", View.VISIBLE,View.GONE,"关闭");
        Log.e("da","token-----"+SpUser.getUserToken(this));
        Log.e("da","terminalid-----"+NetworkUtils.getImeiId(this));
        Log.e("da","userua-----"+baseweb_webview.getSettings().getUserAgentString());
        Log.e("da","userip-----"+NetworkUtils.GetIp());
        initData();

    }
    private void initData() {
        Log.e("jjj","url----"+url.toString());
        if(url!=null&&!url.equals("")){
            baseweb_webview.loadUrl(url.toString());
        }
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && baseweb_webview.canGoBack()) {
            baseweb_webview.goBack();// 返回前一个页面
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
